<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="java.text.*,java.util.*,java.io.*,com.telecom.cms.dao.*,com.telecom.cms.util.*,java.sql.*,com.telecom.cms.util.*,com.telecom.cms.dto.*,org.apache.poi.hssf.usermodel.HSSFWorkbook,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel.HSSFRow,org.apache.poi.hssf.usermodel.HSSFCell"%>
<%
	//response.setContentType(" APPLICATION/OCTET-STREAM ");
	response.reset();
	SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmm");
	java.util.Date today = new java.util.Date();
	String dateToday = dataFormat.format(today);
	response.setContentType("application/vnd.ms-excel");
	response.setHeader(" Content-Disposition ",
	" attachment; filename=\"" + dateToday + ".xls" + "\"");

	HSSFWorkbook wb = new HSSFWorkbook();
	HSSFSheet sheet = wb.createSheet(" sheet1 ");

	List list = (List) request.getSession().getAttribute("Sqllist");

	int num = list.size() + 5;

	List rslist = (List) request.getSession().getAttribute("RSLIST");
	// 以下以写表头
	// 表头为第一行 
	HSSFRow row = sheet.createRow((short) 0);

	HSSFCell cell1 = row.createCell((short) 0);
	HSSFCell cell2 = row.createCell((short) 1);
	HSSFCell cell3 = row.createCell((short) 2);
	HSSFCell cell4 = row.createCell((short) 3);
	HSSFCell cell5 = row.createCell((short) 4);

	cell1.setEncoding((short) 1);
	cell1.setCellType(1);
	cell2.setEncoding((short) 1);
	cell2.setCellType(1);
	cell3.setEncoding((short) 1);
	cell3.setCellType(1);
	cell4.setEncoding((short) 1);
	cell4.setCellType(1);
	cell5.setEncoding((short) 1);
	cell5.setCellType(1);

	// 定义表头的内容 
	cell1.setCellValue(" 产品实例ID ");
	cell1.setCellValue(" 用户名 ");
	cell2.setCellValue(" 接入号码 ");
	cell3.setCellValue(" 账户ID ");
	cell4.setCellValue(" 客户ID ");

	for (int j = 0; j < list.size(); j++) {
		SEG_BIZ_ATOM_DEFDTO dto = (SEG_BIZ_ATOM_DEFDTO) list
		.get(j);
		HSSFCell cell = row.createCell((short) (j + 5));
		cell.setEncoding((short) 1);
		cell.setCellType(1);
		cell.setCellValue(dto.getBIZ_ATOM_NAME());
	}

	for (int i = 0; i < rslist.size(); i++) {

		HSSFRow newrow = sheet.createRow((short) (i + 1));

		String[] cellvalue = (String[]) rslist.get(i);

		for (int k = 0; k < num; k++) {

	HSSFCell cell = newrow.createCell((short) k);
	cell.setEncoding((short) 1);
	cell.setCellType(1);
	cell.setCellValue(cellvalue[k]);

		}

	}

	wb.write(response.getOutputStream());
	response.getOutputStream().flush();
	response.getOutputStream().close();
	out.clear();
	out = pageContext.pushBody();
	Connection con = GetConnect.getCsConnection();
	String userid = (String) session.getAttribute("userid");
	String latnid = (String) session.getAttribute("oldid");
	String pnumber = (String) request.getParameter("pnumber");
	PreparedStatement logps = con.prepareStatement("insert into "
	+ Constant.SEG_USER_EXP_LOG + "  values (?,?,?,?)");
	logps.setString(1, userid);
	logps.setString(2, latnid);
	logps.setString(3, pnumber);
	logps.setString(4, CurrentTime.getCurrentTime());
	logps.execute();
%>
